define(function (require, exports, module) {
    var $ = require('jquery');

    var angular = require('angular');

    var service = angular.module('customMenu.service',[]);
    service.factory('customMenuService',['http','apife','apibe',function(http,apife,apibe){
        var obj ={};

        obj.scope = {} ;

        /**
         * 获得菜单列表
         */
        obj.getMenuList = function(){
            http.post('menu/get-menu-list')
                .success(function(data, status, headers, config) {
                    obj.scope.menuList = data.data || [];
                });
        }
        /**
         * 新增自定义菜单
         * @param params {name : '',level : '', sort : ''}
         */
        obj.addMenu = function(params){
            http.post('menu/add-menu',params)
                .success(function(data, status, headers, config) {
                    obj.getMenuList();
                });
        }
        /**
         * 重命名菜单
         * @param params {id: 菜单id,name: 菜单重命名名称}
         */
        obj.renameMenu = function(params){
            http.post('menu/rename-menu',params)
                .success(function(data, status, headers, config) {
                    obj.getMenuList();
                });
        }
        /**
         * 删除菜单
         * @param params {id: 菜单id}
         */
        obj.deleteMenu = function(params){
            http.post('menu/delete-menu',params)
                .success(function(data, status, headers, config) {
                    obj.getMenuList();
                });
        }
        /**
         * 获得菜单信息
         * @param params {id: 菜单id}
         */
        obj.getMenuInfo = function(params){
            http.post('menu/get-menu-info',params)
                .success(function(data, status, headers, config) {
                    obj.scope = data.data;
                });
        }
        /**
         * 设置菜单的排序
         * @param params {ids: id按序排序逗号分隔从前端传入}
         */
        obj.setMenuSort = function(params){
            http.post('menu/set-menu-sort',params)
                .success(function(data, status, headers, config) {
                    obj.getMenuList();
                });
        }

        /**
         * 重设动作
         * @param params {id: 菜单id}
         */
        obj.resetAction = function(params){
            http.post('menu/reset-action',params)
                .success(function(data, status, headers, config) {
                    obj.scope.changeCurrMenu(data.data,true);
                });
        }
        /**
         * 设置菜单跳转到页面
         * @param params {id: 菜单id,pageUrl: 跳转的url}
         */
        obj.setMenuJumpPage = function(params){
            http.post('menu/set-menu-jump-page',params)
                .success(function(data, status, headers, config) {
                    //obj.scope = data.data;
                    obj.scope.changeCurrMenu(data.data,true);
                });
        }
        /**
         * 设置菜单响应的自动回复消息
         * @param params {id: 菜单id,type: 菜单类型,content: 内容}
         */
        obj.setMenuSendMessage = function(params){
            http.post('menu/set-menu-send-message',params)
                .success(function(data, status, headers, config) {
                    obj.scope.changeCurrMenu(data.data,true);
                });
        }
        obj.publishMenu = function(params){
            http.post('menu/publish-menu')
                .success(function(data, status, headers, config) {
                    $rootScope.$emit('httpRequestSuccess','发布成功！');
                });
        }

        return obj;
    }]);
});